//
//  BDCouponPayTableViewCell.m
//  BadBoy
//
//  Created by wen on 2017/7/7.
//  Copyright © 2017年 com.8xiong. All rights reserved.
//

#import "BDCouponPayTableViewCell.h"
#import "BDShopCouponsModel.h"
@interface BDCouponPayTableViewCell ()

@property (nonatomic, strong) UILabel *currentPriceLabel;
@property (nonatomic, strong) UILabel *oldPriceLabel;
@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UIImageView *titleImageView;
@property (nonatomic, strong) UIView *topLine;
@property (nonatomic, strong) UIView *bottomLine;

@end

@implementation BDCouponPayTableViewCell

- (void)configeWithModel:(id)model shopTitle:(NSString *)shopTitle{
    BDShopCouponsModel *couponModel = model;
    
    self.titleLabel.text = shopTitle;
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:couponModel.cover] placeholderImage:[UIImage imageNamed:@"shop_moren.jpg"]];
    self.textLabel.text = couponModel.title;
    self.currentPriceLabel.text = [NSString stringWithFormat:@"¥%@", [NSDecimalNumber decimalNumberWithString:couponModel.discount_price]];
    self.oldPriceLabel.text = [NSString stringWithFormat:ASLocalizedString(@"原价： ¥%@"), [NSDecimalNumber decimalNumberWithString:couponModel.price]];
    self.timeLabel.text = [NSString stringWithFormat:ASLocalizedString(@"有效期：%@ 至 %@"), couponModel.startTimeString, couponModel.endTimeString];
    
}

- (void)layoutSubviews{
    self.titleImageView.size = CGSizeMake(15, 15);
    self.titleImageView.left = 10;
    self.titleImageView.centerY = 35 / 2.0;
    
    [self.titleLabel sizeToFit];
    self.titleLabel.left = self.titleImageView.right + 6;
    self.titleLabel.centerY = self.titleImageView.centerY;
    
    self.topLine.bottom = 35;
    
    self.imageView.size = CGSizeMake(75, 65);
    self.imageView.left = 10;
    self.imageView.top = self.topLine.bottom + 12;
    
    self.textLabel.font = [UIFont systemFontOfSize:15];
    self.textLabel.textColor = [UIColor colorWithHexString:@"#101010"];
    [self.textLabel sizeToFit];
    self.textLabel.left = self.imageView.right + 10;
    self.textLabel.top = self.imageView.top + 3;
    
    self.currentPriceLabel.font = [UIFont systemFontOfSize:16];
    self.currentPriceLabel.textColor = [UIColor colorWithHexString:@"#ff4f00"];
    [self.currentPriceLabel sizeToFit];
    self.currentPriceLabel.left = self.textLabel.left;
    self.currentPriceLabel.bottom = self.imageView.bottom - 3;
    
    self.oldPriceLabel.font = [UIFont systemFontOfSize:13];
    self.oldPriceLabel.textColor = [UIColor colorWithHexString:@"#999999"];
    [self.oldPriceLabel sizeToFit];
    self.oldPriceLabel.left = self.currentPriceLabel.right + 15;
    self.oldPriceLabel.bottom = self.currentPriceLabel.bottom;
    
    self.bottomLine.top = self.imageView.bottom + 12;
    
    self.timeLabel.font = [UIFont systemFontOfSize:12];
    self.timeLabel.textColor = [UIColor colorWithHexString:@"#999999"];
    [self.timeLabel sizeToFit];
    self.timeLabel.left = 10;
    self.timeLabel.centerY = self.bottomLine.bottom + 17.5;
}

- (UILabel *)timeLabel{
    if (!_timeLabel) {
        self.timeLabel = [[UILabel alloc] init];
        [self.contentView addSubview:_timeLabel];
    }
    return _timeLabel;
}

- (UILabel *)currentPriceLabel{
    if (!_currentPriceLabel) {
        self.currentPriceLabel = [[UILabel alloc] init];
        [self.contentView addSubview:_currentPriceLabel];
    }
    return _currentPriceLabel;
}

- (UILabel *)oldPriceLabel{
    if (!_oldPriceLabel) {
        self.oldPriceLabel = [[UILabel alloc] init];
        [self.contentView addSubview:_oldPriceLabel];
    }
    return _oldPriceLabel;
}

- (UILabel *)titleLabel{
    if (!_titleLabel) {
        self.titleLabel = [[UILabel alloc] init];
        _titleLabel.font = [UIFont systemFontOfSize:15];
        _titleLabel.textColor = [UIColor colorWithHexString:@"#111111"];
        [self.contentView addSubview:_titleLabel];
    }
    return _titleLabel;
}

- (UIImageView *)titleImageView{
    if (!_titleImageView) {
        self.titleImageView = [[UIImageView alloc] init];
        _titleImageView.image = [UIImage imageNamed:@"dianpu"];
        [self.contentView addSubview:_titleImageView];
    }
    return _titleImageView;
}

- (UIView *)topLine{
    if (!_topLine) {
        self.topLine = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kBDScreenWidth, 0.5)];
        _topLine.backgroundColor = [UIColor colorWithHexString:@"#f2f2f2"];
        [self.contentView addSubview:_topLine];
    }
    return _topLine;
}

- (UIView *)bottomLine{
    if (!_bottomLine) {
        self.bottomLine = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kBDScreenWidth, 0.5)];
        _bottomLine.backgroundColor = [UIColor colorWithHexString:@"#f2f2f2"];
        [self.contentView addSubview:_bottomLine];
    }
    return _bottomLine;
}

@end
